from Data_Type import *



class register:
    def __init__(self,value = 0):
        self.content = Word_32bit(value)
        self.value = value
    
    def set(self,value):
        self.content = Word_32bit(value)
        self.value = value

    def __getitem__(self, item):
        return self.content[item]

    def __setitem__(self, item, value):
        self.content[item] = value
        self.value = self.content.val

    def output(self):
        print("$:\t<HEX> 0x%08x\t<DEC> %d" % (self.value, self.value))

class register_file:
    def __init__(self, num=32):
        self.files = [register() for _ in range(num)]
        self.size = num

    def port_IN(self,index,value):
        if index:
            self.files[index].content = Word_32bit(value)
            self.files[index].value = value
    
    def one_port_OUT(self,index):
        return Word_32bit(self.files[index].value)

    def two_port_OUT(self,index_1,index_2):
        return Word_32bit(self.files[index_1].value),Word_32bit(self.files[index_2].value)

    def Show_all_register(self):
        print("#####Register File#####")
        for i in range(self.size):
            print("$%d:\t<HEX> 0x%08x\t<DEC> %d" % (i,self.files[i].value, self.files[i].value))







# reg = register()
# reg.output()

# rf = register_file()
# for i in range(32):
#     rf.port_IN(i,i*2)
# rf.files[31][31] = 1
# a = rf.one_port_OUT(3)
# print(a)
# rf.Show_all_register()